const http=require("http");

const mysql=require("mysql");
const artTemp = require("art-template");

const server=http.createServer(function(request,response){
    
    let conn=mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"films"
    });
    conn.connect();
    conn.query("select * from film_type",function(error,data,fields){
        response.setHeader("Content-Type","text/html;charset=utf-8");
        if(error){
            response.end("<h1 style='color:red'>服务器运行错误</h1>");
            return;
        }
        let temp=artTemp(__dirname+"/template/home.html",{
            list:data
        })
        response.end(temp);
    })
    conn.end();
});

server.listen(3000,function(){
    console.log("服务器启动成功，端口号为localhost:3000");
});